package cn.yqx.bankshop.gateway.config;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

import java.io.IOException;

@Configuration
public class TokenConfig {


    @Bean
    public TokenStore getTokenStore(){
        // 参数不要少了括号
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean // 在 JwtAccessTokenConverter 中定义 Jwt 签名密码
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); // 对称密钥来签署我们的令牌，资源服务器也将使用此秘钥来验证准码性
        ClassPathResource classPathResource = new ClassPathResource("public.txt");
        String publicKey = null ;
        try{
            publicKey = IOUtils.toString(classPathResource.getInputStream(),"utf-8") ;

        }catch (IOException e){

        }
        converter.setVerifierKey(publicKey);
        return converter;
    }
}
